//
//  JFMemberCell.m
//  JobFree2.0
//
//  Created by Dale on 2017/5/31.
//  Copyright © 2017年 Dale. All rights reserved.
//

#import "JFMemberCell.h"
#import "UIImageView+WebCache.h"

@interface JFMemberCell()

@property (strong, nonatomic)  UIImageView *headImg;
@property (strong, nonatomic)  UILabel *nameLB;
@property (nonatomic,strong) UIButton *clickBtn;

@end

@implementation JFMemberCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self headImg];
        [self nameLB];
        [self clickBtn];
    }
    return self;
}

- (UIImageView *)headImg {
    if (_headImg == nil) {
        _headImg = [[UIImageView alloc] init];
        setViewCorner(_headImg, 23);
        [self.contentView addSubview:_headImg];
        [_headImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.mas_equalTo(46);
            make.top.equalTo(self.contentView).offset(8);
            make.centerX.equalTo(self.contentView);
        }];
    }
    return _headImg;
}

- (UIButton *)clickBtn {
    if (_clickBtn == nil) {
        _clickBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_clickBtn setTitle:@"" forState:UIControlStateNormal];
        [_clickBtn addTarget:self action:@selector(handleClickBtnAction) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:_clickBtn];
        [_clickBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.contentView);
        }];
    }
    return _clickBtn;
}

- (UILabel *)nameLB {
    if (_nameLB == nil) {
        _nameLB = [[UILabel alloc] init];
        _nameLB.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:_nameLB];
        [_nameLB mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.contentView);
            make.top.equalTo(self.headImg.mas_bottom).offset(5);
            make.bottom.equalTo(self.contentView);
        }];
    }
    return _nameLB;
}


- (void)setUser:(JFUser *)user {
    _user = user;
    if ([Common isEmptyString:user.user_id]) {
        self.headImg.image = kImage(@"addPerson");
    } else {
        [self.headImg sd_setImageWithURL:[NSURL URLWithString:user.head_image_url] placeholderImage:kImage(@"touxiang") options:SDWebImageRetryFailed];
    }
    self.nameLB.text = user.user_name;
}

- (void)handleClickBtnAction {
    if (self.clickMemberBtnBlock) {
        if ([Common isEmptyString:_user.user_id]) {
            self.clickMemberBtnBlock(JFMemberCellTypeAdd);
        } else {
            self.clickMemberBtnBlock(JFMemberCellTypePerson);
        }
    }
    
}



@end
